//
//  LoginViewController.m
//  YYPHSpeedJump
//
//  Created by sujiang on 15/12/17.
//  Copyright © 2015年 sujiang. All rights reserved.
//

#import "HomeViewController.h"
#import "RootViewController.h"
#import "LoginViewController.h"
#import "InvationCode.h"
#import "BaseNavigationController.h"

@interface HomeViewController ()
{
    UIImageView *bgImageView;
    UIButton *loginBtn;
    UIButton *registBtn;
    UIButton *justSeeBtn;
}
@end

@implementation HomeViewController

- (void)loadView
{

    bgImageView = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    bgImageView.image = [UIImage imageNamed:@"bg"];
    bgImageView.userInteractionEnabled = YES;
    self.view = bgImageView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addButtons];
}

- (void)addButtons
{
    loginBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    loginBtn.frame = CGRectMake(31, 466.5 * kHeightScale, kScreenWidth - 2 * 31, 49 * kHeightScale);
    [bgImageView addSubview:loginBtn];
    [loginBtn setBackgroundImage:[UIImage imageNamed:@"denglu"] forState:(UIControlStateNormal)];
    [loginBtn addTarget:self action:@selector(actionLoginBtn:) forControlEvents:(UIControlEventTouchUpInside)];
    
    
    registBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    registBtn.frame = CGRectMake(loginBtn.left, loginBtn.bottom + 17, loginBtn.width, loginBtn.height);
    [bgImageView addSubview:registBtn];
    [registBtn setBackgroundImage:[UIImage imageNamed:@"zhuce"] forState:(UIControlStateNormal)];
    [registBtn addTarget:self action:@selector(actionRegistBtn:) forControlEvents:(UIControlEventTouchUpInside)];
    
    justSeeBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    justSeeBtn.frame = CGRectMake(registBtn.right - 80, registBtn.bottom + 8, 80, 40);
    justSeeBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    justSeeBtn.titleLabel.textAlignment = NSTextAlignmentRight;
    [bgImageView addSubview:justSeeBtn];
    NSMutableAttributedString *title = [[NSMutableAttributedString alloc] initWithString:@"先去逛逛"];
    NSRange titleRange = {0,[title length]};
    [title addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:titleRange];
    [title addAttribute:NSForegroundColorAttributeName value:kColors(255, 255, 255, 1) range:titleRange];
    
    [justSeeBtn setAttributedTitle:title forState:(UIControlStateNormal)];
    [justSeeBtn addTarget:self action:@selector(actionJustSeeBtn:) forControlEvents:(UIControlEventTouchUpInside)];
    
    
}

#pragma mark -- 点击按钮响应事件
- (void)actionLoginBtn:(UIButton *)button
{
    // 登录按钮
    LoginViewController *loginVC = [[LoginViewController alloc] init];
    UINavigationController *naviVC = [[UINavigationController alloc] initWithRootViewController:loginVC];
    [self presentViewController:naviVC animated:YES completion:nil];
}

- (void)actionRegistBtn:(UIButton *)button
{
    // 注册按钮
   
    InvationCode *invaVC = [[InvationCode alloc] init];
    BaseNavigationController *naviVC = [[BaseNavigationController alloc] initWithRootViewController:invaVC];
    [self presentViewController:naviVC animated:YES completion:nil];
    
    
}

- (void)actionJustSeeBtn:(UIButton *)button
{
    // 先去逛逛
    RootViewController *rootVC = [[RootViewController alloc] init];
    [self presentViewController:rootVC animated:YES completion:nil];
    [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"logined"];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
